"use strict";
cc._RF.push(module, 'ec242ucTw5L6IDu4ClT+6Wt', 'BackgroundFitter');
// eazax-ccc/components/BackgroundFitter.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var EventManager_1 = require("../core/EventManager");
var _a = cc._decorator, ccclass = _a.ccclass, executionOrder = _a.executionOrder;
/**
 * 背景适配组件
 * @see BackgroundFitter.ts https://gitee.com/ifaswind/eazax-ccc/blob/master/components/BackgroundFitter.ts
 * @version 20210504
 */
var BackgroundFitter = /** @class */ (function (_super) {
    __extends(BackgroundFitter, _super);
    function BackgroundFitter() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    BackgroundFitter.prototype.onLoad = function () {
        this.registerEvent();
    };
    BackgroundFitter.prototype.onEnable = function () {
        this.adapt();
    };
    BackgroundFitter.prototype.onDestroy = function () {
        this.unregisterEvent();
    };
    /**
     * 订阅事件
     */
    BackgroundFitter.prototype.registerEvent = function () {
        EventManager_1.default.on('view-resize', this.adapt, this);
    };
    /**
     * 取消事件订阅
     */
    BackgroundFitter.prototype.unregisterEvent = function () {
        EventManager_1.default.off('view-resize', this.adapt, this);
    };
    /**
     * 适配
     */
    BackgroundFitter.prototype.adapt = function () {
        // 实际屏幕比例
        var winSize = cc.winSize, screenRatio = winSize.height / winSize.width;
        // 设计比例
        var designResolution = cc.Canvas.instance.designResolution, designRatio = designResolution.height / designResolution.width;
        var scale = 1;
        if (screenRatio >= designRatio) {
            scale = winSize.height / designResolution.height;
        }
        else {
            scale = winSize.width / designResolution.width;
        }
        this.node.scale = scale;
    };
    BackgroundFitter = __decorate([
        ccclass,
        executionOrder(-99)
    ], BackgroundFitter);
    return BackgroundFitter;
}(cc.Component));
exports.default = BackgroundFitter;

cc._RF.pop();